<?php
/**
 * Created by PhpStorm.
 * User: ITS Lab
 * Date: 2016/2/4
 * Time: 15:38
 */
namespace Home\Controller;
use Think\Controller;

class UserController extends Controller
{

    public function index()
    {
        header("Content-type:text/html;charset=utf-8");
        //导航条的时间分类
        $today = date("Y-m-d");
        $yesterday = date("Y-m-d", strtotime("-1 day"));
        $twoDaysAgo = date("Y-m-d", strtotime("-2 day"));
        $threeDaysAgo = date("Y-m-d", strtotime("-3 day"));
        $fourDaysAgo = date("Y-m-d", strtotime("-4 day"));
        $fiveDaysAgo = date("Y-m-d", strtotime("-5 day"));
        $this->assign('today', $today);
        $this->assign('yesterday', $yesterday);
        $this->assign('twoDaysAgo', $twoDaysAgo);
        $this->assign('threeDaysAgo', $threeDaysAgo);
        $this->assign('fourDaysAgo', $fourDaysAgo);
        $this->assign('fiveDaysAgo', $fiveDaysAgo);
        $lost_thing_record = D('kind')->getKindName();
        $this->FoundRecord = $lost_thing_record;
        $uid= $_SESSION['uid'];
        $m=M('user');
        $where['bbs_uid']=$uid;
        $data=$m->where($where)->find();
        $user_id=$data['id'];
        $m=M('thing');
        $where['user_id']=$user_id;
       $data=$m->where($where)->select();
       for($i=0;$i<count($data);$i++)
       {
           if($data[$i]['lost_or_pick']==0)
               $data[$i]['lost_or_pick']='丢失';
           else
               $data[$i]['lost_or_pick']='捡到';
           if($data[$i]['status']==0)
               $data[$i]['status']='未认领';
           else
               if($data[$i]['status']==1)
                   $data[$i]['status']='已认领';
           else
               if($data[$i]['status']==2)
                   $data[$i]['status']='认领过期';
           else
               if($data[$i]['status']==3)
                   $data[$i]['status']='认领完成';
           $where['id']=$data[$i]['kind_id'];
           $m=M('kind');
           $kind=$m->where($where)->field('name')->find();
           $data[$i]['kind']=$kind['name'];
       }
        $this->username=$_SESSION['username'];
        $this->FoundRecord1=$data;
        //var_dump($data);
        //var_dump($data);
       $this->assign('servername',$_SERVER['SERVER_NAME']);
        $this->display();
    }
    public  function ajax()
    {
        $thing_id=I('post.thing_id');
        $where['id']=$thing_id;
        $m=M('thing');
       $data=$m->where($where)->field('status')->find();
        $data['status']=3;
        $m->where($where)->save($data);
        $m=M('trade_record');
        $where1['thing_id']=$thing_id;
        $data=$m->where($where1)->field('is_success')->find();
        $data1['is_success']=1;
        $m->where($where1)->save($data1);
        $this->ajaxReturn($data);
    }
    public  function addition()//点击显示详细描述
    {
        $where['id']= I('get.id');
        $m=M('thing');
       $data=$m->where($where)->field('description')->find();
        $this->ajaxReturn($data);
    }
   public function  mobile()
   {

          header("Content-type:text/html;charset=utf-8");
        //导航条的时间分类
        $today = date("Y-m-d");
        $yesterday = date("Y-m-d", strtotime("-1 day"));
        $twoDaysAgo = date("Y-m-d", strtotime("-2 day"));
        $threeDaysAgo = date("Y-m-d", strtotime("-3 day"));
        $fourDaysAgo = date("Y-m-d", strtotime("-4 day"));
        $fiveDaysAgo = date("Y-m-d", strtotime("-5 day"));
        $this->assign('today', $today);
        $this->assign('yesterday', $yesterday);
        $this->assign('twoDaysAgo', $twoDaysAgo);
        $this->assign('threeDaysAgo', $threeDaysAgo);
        $this->assign('fourDaysAgo', $fourDaysAgo);
        $this->assign('fiveDaysAgo', $fiveDaysAgo);
        $lost_thing_record = D('kind')->getKindName();
        $this->FoundRecord = $lost_thing_record;
        $uid= $_SESSION['uid'];
        $m=M('user');
        $where['bbs_uid']=$uid;
        $data=$m->where($where)->find();
        $user_id=$data['id'];
        $m=M('thing');
        $where['user_id']=$user_id;
       $data=$m->where($where)->select();
       for($i=0;$i<count($data);$i++)
       {
           if($data[$i]['lost_or_pick']==0)
               $data[$i]['lost_or_pick']='丢失';
           else
               $data[$i]['lost_or_pick']='捡到';
           if($data[$i]['status']==0)
               $data[$i]['status']='未认领';
           else
               if($data[$i]['status']==1)
                   $data[$i]['status']='已认领';
           else
               if($data[$i]['status']==2)
                   $data[$i]['status']='认领过期';
           else
               if($data[$i]['status']==3)
                   $data[$i]['status']='认领完成';
           $where['id']=$data[$i]['kind_id'];
           $m=M('kind');
           $kind=$m->where($where)->field('name')->find();
           $data[$i]['kind']=$kind['name'];
       }
        $this->username=$_SESSION['username'];
        $this->uid=$_SESSION['uid'];
        $this->FoundRecord1=$data;
    $this->assign('servername',$_SERVER['SERVER_NAME']);
       $this->display();
   }
     function _empty(){
        header("HTTP/1.0 404 Not Found");//使HTTP返回404状态码
        $this->display("Error:error404");
    }
}
